﻿using System;
using core;

namespace tester
{
    public class lang
    {
        public const string FORM_HW_INFO_TEXT_1_1 = "Áno";
        public const string FORM_HW_INFO_TEXT_1_2 = "Nie";
        public const string FORM_HW_INFO_TEXT_2_1 = "Názov";
        public const string FORM_HW_INFO_TEXT_2_2 = "Popis";
        public const string FORM_HW_INFO_TEXT_2_3 = "64 bit. architúra";
    }

    /// <summary>Trieda IHardwareInfo</summary>
    public class IHardwareInfo : IDisposable
    {
        public class IParamInfo
        {
            public string ID;
            public string Name;
            public string Value;

            public IParamInfo(string pID, string pName, string pValue)
            {
                ID = pID;
                Name = pName;
                Value = pValue;
            }
        }

        public System.Collections.Generic.List<IParamInfo> Processor;

        /// <summary>Konstruktor</summary>
        public IHardwareInfo()
        {
            Processor = new System.Collections.Generic.List<IParamInfo>();
        }
        /// <summary>Dispose metoda</summary>
        public void Dispose() 
        {
            if (Processor == null) return;
            Processor.Clear(); Processor = null;
        }

        /// <summary>Nacitanie informacii o procesore</summary>
        /// <returns>true / false</returns>
        public bool ReadInfo_Processor()
        {
            try
            {
                Processor.Clear(); // Vymazem aktualny obsah
                System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
                foreach (System.Management.ManagementObject queryObj in searcher.Get())
                {
                    foreach (System.Management.PropertyData D in queryObj.Properties)
                    {
                        string N = D.Name.ToLower();
                        switch (N)
                        {
                            case "name": Processor.Add(new IParamInfo(N, lang.FORM_HW_INFO_TEXT_2_1, ICore.ToStr(D.Value))); break;
                            case "caption": Processor.Add(new IParamInfo(N, lang.FORM_HW_INFO_TEXT_2_2, ICore.ToStr(D.Value))); break;
                            case "addresswidth": Processor.Add(new IParamInfo(N, lang.FORM_HW_INFO_TEXT_2_3, ICore.ToInt(D.Value) == 64 ? lang.FORM_HW_INFO_TEXT_1_1 : lang.FORM_HW_INFO_TEXT_1_2)); break;
                        }
                    }
                }
                return true; // OK
            }
            catch
            {
                return false; // Chyba
            }
        }
    }

    public class temp
    {
        public static void Run()
        {
            System.Management.ManagementObjectSearcher searcher =
                        new System.Management.ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
            foreach (System.Management.ManagementObject queryObj in searcher.Get())
            {
                foreach (System.Management.PropertyData D in queryObj.Properties)
                {
                    Console.WriteLine("[{0}]: [{1}]", D.Name, D.Value);
                }
            }

            IHardwareInfo Info = new IHardwareInfo();
            if (!Info.ReadInfo_Processor()) return;

            Console.WriteLine("------------------------------------------------");
            foreach (IHardwareInfo.IParamInfo I in Info.Processor)
            {
                Console.WriteLine("[{0}] [{2}]: [{1}]", I.ID, I.Value, I.Name);
            }
        }
    }
}
